package com.config.quartz;

import com.service.WebsiteVisitorService;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

//使用定时任务的方式 取处理数据库的数据
@Component
@Log4j2
public class QuartzDatabase implements Job {

    @Autowired
    private WebsiteVisitorService websiteVisitorService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //System.out.println(LocalDateTime.now().toString()+":一直执行，每隔60秒执行一次");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String start ="开始执行定时任务"+simpleDateFormat.format(new Date());
        log.info(start);

        websiteVisitorService.handleVisitorApiAbnormal();
        websiteVisitorService.handleVisitorAbnormal();

        String end = "结束执行定时任务"+simpleDateFormat.format(new Date());
        log.info(end);


    }
}
